package cn.wzvtc.inheritance_interface;

import java.util.Collections;
import java.util.Objects;

/**
 * @author Shiwei Xu
 * @date 2020/4/21
 */
public class Student {

  private Integer id;

  private String name;

  public Student(Integer id, String name) {
    this.id = id;
    this.name = name;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Student student = (Student) o;
    // 如果按下面这么写，如果id为null，会抛异常！！！
//    return id.equals(student.id);
    // 今后，判断两个对象是否equals，建议用Objects.equals，因为可以避免NPE
    return Objects.equals(id, student.id);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id);
  }

  @Override
  public String toString() {
    return "Student{" +
        "id=" + id +
        ", name='" + name + '\'' +
        '}';
  }
}
